<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>账号注册</title>
</head>
<link rel="stylesheet" href="../src/css/public.css">
<link rel="stylesheet" href="../src/css/in.css">

<body>
    <header>
        <div class="center header-top">
            <span>一年逛两次 <img src="../static/img/logo.png" alt=""> 每次都有新选择！</span>
            <ul>
                <li class="my"></li>
                <li><a href="./login.html" title="登录">登录</a></li>
                <li><a href="register.html" title="注册账号">注册</a></li>
                <li><a href="../index.html" title="主页">主页</a></li>
                <li class="call"><a href="call.html" title="call me">联系我们</a></li>
            </ul>
        </div>
    </header>
    <div class="register">
        <div class="logo-one"><a href="../index.html">
            <img src="../static/img/logo (4).png" alt="" title="super clothes"></a>
        </div>
        <h3>注册账号</h3>
        <form action="javascript:;">
            <table>
                <tr>
                    <td>账号：</td>
                    <td> <input type="text" name="username"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>账号由6~16位的数字、字母和汉字组成</td>
                </tr>
                <tr>
                    <td>密码：</td>
                    <td> <input type="password" name="password"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>密码由6~18位的数字、字母、下划线组成</td>
                </tr>
                <tr>
                    <td>重输密码：</td>
                    <td> <input type="password" name="repassword"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>请再次输入您的密码</td>
                </tr>
                <tr>
                    <td>手机号：</td>
                    <td> <input type="number" name="phone"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>该手机号仅注册时使用，不会有其他用途</td>
                </tr>
                <tr>
                    <td>邮箱：</td>
                    <td> <input type="email" name="email"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>请填写正确的邮箱以方便您后期找回密码</td>
                </tr>
                <tr>
                    <td></td>
                    <td> <input type="checkbox" name="xieyi"> <span class="orz">同意《服务条款》和《隐私政策》</span> </td>
                </tr>
                <tr>
                    <td></td>
                    <td> <button>立即注册</button></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td></td>
                    <td>已有账号？ <a href="./login.html">去登录</a></td>
                </tr>
            </table>
        </form>
    </div>

    <footer>
        <p>北京超衣设计文化有限公司 京网文[2019]10010-8848号 京ICP备12008848号</p>
        <p>Copyright © Shifone 2019 - 2080 All rights reserved.</p>

    </footer>
</body>
<script src="../dist/js/jquery.min.js"></script>
<script src="../src/js/public.js"></script>
<script src="../src/js/promiseAjax.js"></script>
<script type="text/javascript">
    document.querySelector("button").onclick = function () {
        var username = document.querySelector('input[name="username"]').value.trim();
        usernameReg = /^[0-9a-zA-Z\u4e00-\u9fa5]{6,16}$/;
        if (!usernameReg.test(username)) {
            alert("用户名不符合规则");
            return false;
        }
        var password = document.querySelector('input[name="password"]').value.trim();
        var passwordReg = /^\w{6,18}$/;
        if (!passwordReg.test(password)) {
            alert("密码不符合规则");
            return false;
        }
        var repass = document.querySelector('input[name="repassword"]').value.trim();
        if (password != repass) {
            alert("两次密码不一致");
            return false;
        }
        var phone = document.querySelector('input[name="phone"]').value.trim();
        phoneReg =
            /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/;
        if (!phoneReg.test(phone)) {
            alert("请输入正确的手机号");
            return false;
        }
        var email = document.querySelector('input[name="email"]').value.trim();
        emailReg = /^\w*@(126|qq|163|sina|gmail)\.(com|cn)$/;
        if (!emailReg.test(email)) {
            alert("请输入正确的电子邮箱");
            return false;
        }

        var xieyi = document.querySelector("input[name='xieyi']").checked;
        if (!xieyi) {
            alert("请同意协议");
            return false;
        }
        PAjax({
            method: "post",
            url: "../api/register.php",
            data: {
                uname: username,
                pass: password,
                phone: phone,
                email: email
            },
            async: true,
            success: function (res) {
                resolve(res);
            }
        }).then(function (res) {
            res = JSON.parse(res);
            if (res.status === 2) {
                alert(res.msg);
                
                location.href = 'login.html';
            } else if (res.status == 1) {
                alert(res.msg);
                return false;
            } else if (res.status == 3) {
                alert(res.msg);
                return false;
            } else if (res.status == 101) {
                alert(res.msg);
                return false;
            } else if (res.status == 102) {
                alert(res.msg);
                return false;
            } else if (res.status == 4) {
                alert(res.msg);
                return false;
            }
        });
    }
</script>

</html>